public class Text3 {
    //1004.最大连续1的个数
    public int longestOnes(int[] nums, int k) {
        int left = 0, right = 0, ret = 0;
        int zero = 0;
        while(right < nums.length){
            if (nums[right] == 0) {zero++;}
            while(zero > k) {
               if (nums[left] == 0){zero--;}
                  left++;
            }
            ret = Math.max(ret,right-left+1);
            right++;
        }
        return ret;
    }
}
